package cs2340.droidceptiontodo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
/**
 * Displays all of a to-do item's attributes
 * Contains a button that leads to the edit item screen
 * 
 * @author Roberta Reusch-Lewis
 *
 */
public class ViewToDoItemActivity extends Activity implements OnClickListener{
	public static ToDoItem item;
	private TextView name, category, date, time, description, location;
	private Button editButton, doneButton;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_todoitem);
        Log.d("DEBUG","Starting ViewToDoItem Activity");
        
        name = (TextView)findViewById(R.id.title);
        category = (TextView)findViewById(R.id.category);
        date = (TextView)findViewById(R.id.date);
        time = (TextView)findViewById(R.id.time);
        description = (TextView)findViewById(R.id.description);
        location = (TextView)findViewById(R.id.location);
        editButton = (Button)findViewById(R.id.editButton);
        editButton.setOnClickListener(this);
        doneButton = (Button)findViewById(R.id.doneButton);
        doneButton.setOnClickListener(this);
        
        // Set text views to match current item
        name.setText(item.getName().toString());
        category.setText(item.getCategory().toString());
        date.setText(item.getDueDate());
        time.setText(item.getDueTime());
        description.setText(item.getDetails());
        location.setText(item.getLocation().toString());
	}

	/**
	 * Called when the edit or done button is clicked
	 */
	@Override
	public void onClick(View v) {
		// edit the current item
		if (v.getId() == editButton.getId()) {
			EditToDoItemActivity.item = item;
			Intent i = new Intent();
			i.setClassName("cs2340.droidceptiontodo", "cs2340.droidceptiontodo.EditToDoItemActivity");
			startActivity(i);
		}
		// return to home screen
		else if (v.getId() == doneButton.getId()) {
			Intent i = new Intent();
			i.setClassName("cs2340.droidceptiontodo", "cs2340.droidceptiontodo.ToDoItemsActivity");
			startActivity(i);
		}
	}
}
